﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApiTest.Dto.Utils;
using WebApiTest.Models;
using WebApiTest.Service.Office;

namespace WebApiTest.Controllers.office
{
    [Route("api/[controller]")]
    [ApiController]
    public class StatisticsController : ControllerBase
    {
        private StatisticsService statisticsService = new StatisticsService();

        [HttpPost("groupByType")]
        public TableRspDTO groupByType(TableReqDTO tableReqDTO)
        {
            TableRspDTO tableRspDTO = new TableRspDTO();
            try
            {
                tableRspDTO = statisticsService.groupByType(tableReqDTO);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return tableRspDTO;
        }

        [HttpPost("groupByPerson")]
        public TableRspDTO groupByPerson(TableReqDTO tableReqDTO)
        {
            TableRspDTO tableRspDTO = new TableRspDTO();
            try
            {
                tableRspDTO = statisticsService.groupByPerson(tableReqDTO);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return tableRspDTO;
        }

        [HttpPost("groupByDept")]
        public TableRspDTO groupByDept(TableReqDTO tableReqDTO)
        {
            TableRspDTO tableRspDTO = new TableRspDTO();
            try
            {
                tableRspDTO = statisticsService.groupByDept(tableReqDTO);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return tableRspDTO;
        }
    }
}
